<?php 

class App_Model_DbTable_Article_Type_Video_Data extends Ext_Db_Table  
{  
    protected $_name = 'article_type_video_data';
    
	public function get($id)
	{
		if(!$id)
		{
			return "";
		}
		
		$db = $this->getAdapter();
		$safe = $db->quoteInto(" id = ? ", $id);
		$row = $this->fetchRow($safe);
		if (!$row) {
			//throw new Exception("Count not find row $id");
			return "";
		}
		return $row->toArray();
	}

	public function getAllById($idArray)
	{
		if(!$idArray)
		{
			return "";
		}
		
		$db = $this->getAdapter();
		$safe = $db->quoteInto(" id IN(?) ", $idArray);
		$all = $this->fetchAll($safe);
		if (!$all) {
			//throw new Exception("Count not find row $id");
			return "";
		}
		return $all->toArray();
	}

	public function del($id)
	{
		if(!$id)
		{
			return "";
		}
		
		$db = $this->getAdapter();
		$safe = $db->quoteInto(" id = ? ", $id);
		$rows_affected = $this->delete($safe);
		
		return $rows_affected;
	}
	
	public function addOld($inputArray, $dataId)
	{
		$sql_data_array = array();
		if(array_key_exists('description', $inputArray)) $sql_data_array['description'] = $inputArray['description'];
		if(array_key_exists('htmlOn', $inputArray)) $sql_data_array['htmlOn'] = $inputArray['htmlOn'];
		if(!$sql_data_array)
		{
			return "";
		}

		try {
			$db = $this->getAdapter();
			$where = $db->quoteInto(" id = ? ", $dataId);
			$rows_affected = $this->update($sql_data_array, $where);
		}catch (Exception $e){
			trigger_error($e->getMessage(), E_USER_WARNING);
		}
		
		return "";
	}
	
	public function addNew($inputArray)
	{
		$sql_data_array = array();
		if(array_key_exists('articleId', $inputArray)) $sql_data_array['articleId'] = $inputArray['articleId'];
		if(array_key_exists('videoId', $inputArray)) $sql_data_array['videoId'] = $inputArray['videoId'];
		if(array_key_exists('title', $inputArray)) $sql_data_array['title'] = $inputArray['title'];
		if(array_key_exists('description', $inputArray)) $sql_data_array['description'] = $inputArray['description'];
		if(array_key_exists('htmlOn', $inputArray)) $sql_data_array['htmlOn'] = $inputArray['htmlOn'];

		try {
			// 插入数据行并返回插入的行数
			$rows_affected = $this->insert($sql_data_array);
			$dataId = $this->getAdapter()->lastInsertId();
		}catch (Exception $e){
			trigger_error($e->getMessage(), E_USER_WARNING);
		}

		return $dataId;	
	}
}